﻿using System;
using System.Runtime.Serialization;
using Maple.Weixin.MP.Cryptography;

namespace Maple.Weixin.MP.Exceptions
{
    /// <summary>
    /// 消息加解密错误，只要加解密操作返回不为0就是该类异常。
    /// </summary>
    public class MessageEncryptingException : Exception
    {
        private readonly WXBizMsgCryptErrorCode errorCode;

        public MessageEncryptingException(WXBizMsgCryptErrorCode errorCode) {
            this.errorCode = errorCode;
        }

        public MessageEncryptingException(int code) {
            this.errorCode = (WXBizMsgCryptErrorCode) code;
        }

        public MessageEncryptingException(string message, WXBizMsgCryptErrorCode errorCode)
            : base(message) {
            this.errorCode = errorCode;
        }

        public MessageEncryptingException(string message, int code) : base(message) {
            this.errorCode = (WXBizMsgCryptErrorCode) code;
        }

        public MessageEncryptingException(SerializationInfo info, StreamingContext context,
            WXBizMsgCryptErrorCode errorCode)
            : base(info, context) {
            this.errorCode = errorCode;
        }

        public MessageEncryptingException(SerializationInfo info, StreamingContext context, int code)
            : base(info, context) {
            this.errorCode = (WXBizMsgCryptErrorCode) code;
        }

        public WXBizMsgCryptErrorCode ErrorCode {
            get { return errorCode; }
        }
    }
}
